package com.bootcamp.javase.object;

/**
 * @program: ObjectCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-06 20:42
 **/

public class StringTest {


    public static void main(String[] args) {
//        String strl = "woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun";
        String strl = "javajavajavajavajavajavajavajavajavajavajavajava";
        String strs = "java";
        System.out.println("出现了 "+calcFreq(strl, strs)+" 次");
    }

    private static int calcFreq(String strl, String strs){
        int fromStart = 0;
        int count = 0;
        int lenl = strl.length();
        int lens = strs.length();
        while (fromStart+lens <= lenl){
            int index = strl.indexOf(strs,fromStart);
            if (index==-1)
                break;
            count++;
            fromStart  = index+lens;
        }
        return count;
    }
}
